package com.jc.camerascan.adapter.mine;

import android.graphics.Paint;
import android.view.View;
import android.widget.TextView;

import androidx.constraintlayout.widget.ConstraintLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.jc.camerascan.R;
import com.jc.camerascan.entity.GetProductListResult;
import com.jc.camerascan.entity.HomeMenu;
import com.jc.camerascan.entity.event.PriceSelectEvent;
import com.jc.camerascan.utils.ImageUtil;
import com.xuexiang.xui.utils.DensityUtils;
import com.xuexiang.xui.widget.imageview.RadiusImageView;
import com.xuexiang.xui.widget.layout.XUIRelativeLayout;

import org.greenrobot.eventbus.EventBus;

import static com.xuexiang.xui.widget.layout.IXUILayout.HIDE_RADIUS_SIDE_NONE;

/**
 * @Package: com.jc.camerascan.adapter.mine
 * @Description: java类作用描述
 * @Author: xuchi
 * @CreateDate: 2020/8/2 17:39
 * @Version: 1.0
 */
public class PricesetAdapter extends BaseQuickAdapter<GetProductListResult, BaseViewHolder> {

    public PricesetAdapter() {
        super(R.layout.item_price);
    }

    @Override
    protected void convert(BaseViewHolder helper, GetProductListResult item) {
        helper.setText(R.id.title, item.getProduct_name());

        ConstraintLayout priceLayout = helper.getView(R.id.price_layout);

        String price_str = item.getPrice() + "";
        if (price_str.endsWith(".0")) {
            price_str = price_str.replace(".0", "");
        }
        if (price_str.endsWith(".00")) {
            price_str = price_str.replace(".00", "");
        }
        helper.setText(R.id.price, price_str);

        if (item.isSelected()) {
            priceLayout.setBackgroundResource(R.drawable.price_selected);
        } else {
            priceLayout.setBackgroundResource(R.drawable.price_unselected);
        }
        priceLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EventBus.getDefault().post(new PriceSelectEvent(helper.getPosition()));
            }
        });

        TextView oldPrice = helper.getView(R.id.old_price);
        oldPrice.setText("原价￥" + item.getOld_price());
        oldPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        oldPrice.getPaint().setAntiAlias(true);//抗锯齿
    }
}
